<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAllTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //$table->integer('type')->nullable()->default(1)->comment('1不首页2首页');
        // $table->string('img_url')->nullable()->comment('图标');
        // $table->unsignedDecimal('back_price',11,2)->default('0.00')->nullable()->comment('退款金额');
        Schema::create('adminuser', function (Blueprint $table) {//管理员
            $table->increments('id');
            $table->string('username')->nullable()->comment('帐号');
            $table->string('password')->nullable()->comment('密码');
            $table->string('name')->nullable()->comment('姓名');
            $table->string('mobile')->nullable()->comment('手机号');
            $table->integer('type')->nullable()->comment('权限 1超级管理员2收银台');
            $table->string('login_token')->nullable()->comment('登录token');
            $table->string('token_time')->nullable()->comment('登录时间');
            $table->integer('state')->nullable()->default(1)->comment('状态1正常 2关闭');
            $table->timestamps();
        });
        Schema::create('users', function (Blueprint $table) {//用户
            $table->increments('id');
            $table->string('openid')->nullable()->comment('openid');
            $table->string('avatar')->nullable()->comment('头像');
            $table->string('nickname')->nullable()->comment('昵称');
            $table->string('mobile')->nullable()->comment('手机号');
            $table->unsignedDecimal('balance',11,2)->default('0.00')->nullable()->comment('余额');
            $table->string('login_token')->nullable()->comment('登录token');
            $table->string('token_time')->nullable()->comment('登录时间');
            $table->integer('state')->nullable()->default(1)->comment('状态1正常 2关闭');
            $table->timestamps();
        });
        Schema::create('address', function (Blueprint $table) {//用户地址
            $table->increments('id');
            $table->integer('userid')->nullable()->comment('用户id');
            $table->string('name')->nullable()->comment('姓名');
            $table->string('mobile')->nullable()->comment('手机号');
            $table->string('city')->nullable()->comment('城市');
            $table->string('area')->nullable()->comment('地区');
            $table->string('street')->nullable()->comment('街道');
            $table->string('address')->nullable()->comment('详细地址');
            $table->integer('state')->default(2)->comment('默认 1默认 2不默认');
            $table->timestamps();
        });
        Schema::create('userslog', function (Blueprint $table) {//用户充值 消费记录
            $table->increments('id');
            $table->integer('userid')->nullable()->comment('用户id');
            $table->string('order_sn')->nullable()->comment('订单号');
            $table->unsignedDecimal('price',11,2)->nullable()->comment('金额');
            $table->integer('type')->default(1)->comment('类型 1充值 2消费 3退款');
            $table->timestamps();
        });
        Schema::create('recharge', function (Blueprint $table) {//微信充值
            $table->increments('id');
            $table->string('name')->nullable()->comment('名称');
            $table->unsignedDecimal('price',11,2)->nullable()->comment('充值金额');
            $table->string('back_price')->nullable()->comment('充值返现金额');
            $table->string('start_time')->nullable()->comment('开始时间');
            $table->string('end_time')->nullable()->comment('结束时间');
            $table->integer('state')->default(1)->comment('类型 1正常 2关闭');
            $table->timestamps();
        });
        Schema::create('guige', function (Blueprint $table) {//规格
            $table->increments('id');
            $table->string('name')->nullable()->comment('名称');
            $table->timestamps();
        });
        Schema::create('product', function (Blueprint $table) {//产品
            $table->increments('id');
            $table->integer('ggid')->nullable()->comment('规格id');
            $table->integer('category')->nullable()->comment('分类id');
            $table->string('name')->nullable()->comment('名称');
            $table->string('thumb')->nullable()->comment('缩略图');
            $table->string('image')->nullable()->comment('轮播');
            $table->string('des')->nullable()->comment('描述');
            $table->unsignedDecimal('price',11,2)->nullable()->comment('价格');
            $table->string('sort')->nullable()->default(0)->comment('排序');
            $table->integer('is_tj')->nullable()->default(1)->comment('是否推荐');
            $table->integer('state')->nullable()->default(1)->comment('1上架 2下架');
            $table->timestamps();
        });
        Schema::create('category', function (Blueprint $table) {//产品分类
            $table->increments('id');
            $table->string('name')->nullable()->comment('名称');
            $table->string('thumb')->nullable()->comment('主图');
            $table->string('sort')->nullable()->default(0)->comment('排序');
            $table->timestamps();
        });
        Schema::create('order', function (Blueprint $table) {//订单
            $table->increments('id');
            $table->integer('userid')->nullable()->comment('用户id');
            $table->integer('preferid')->nullable()->comment('优惠券id');
            $table->string('order_sn')->nullable()->comment('订单号');
            $table->unsignedDecimal('price',11,2)->nullable()->comment('价格');
            $table->unsignedDecimal('yhprice',11,2)->default('0.00')->nullable()->comment('优惠金额');
            $table->unsignedDecimal('psprice',11,2)->default('0.00')->nullable()->comment('配送金额');
            $table->string('city')->nullable()->comment('城市');
            $table->string('area')->nullable()->comment('区域');
            $table->string('street')->nullable()->comment('街道');
            $table->string('address')->nullable()->comment('详细地址');
            $table->integer('type')->nullable()->comment('支付类型 1微信 2余额');
            $table->integer('state')->nullable()->comment('状态 1未支付 2已支付 3已完成 4已退款');
            $table->string('bz')->nullable()->comment('备注');
            $table->timestamps();
        });
        Schema::create('orderproduct', function (Blueprint $table) {//订单产品
            $table->increments('id');
            $table->integer('orderid')->nullable()->comment('订单id');
            $table->string('guige')->nullable()->comment('规格');
            $table->string('name')->nullable()->comment('名称');
            $table->string('thumb')->nullable()->comment('缩略图');
            $table->unsignedDecimal('price',11,2)->nullable()->comment('价格');
            $table->integer('num')->nullable()->comment('购买数量');
            $table->string('des')->nullable()->comment('描述');
            $table->timestamps();
        });
        Schema::create('cart', function (Blueprint $table) {//购物车 
            $table->increments('id');
            $table->integer('userid')->nullable()->comment('用户id');
            $table->integer('proid')->nullable()->comment('商品id');
            $table->integer('addrid')->nullable()->comment('地址id');
            $table->unsignedDecimal('price',11,2)->nullable()->comment('价格');
            $table->integer('num')->nullable()->comment('购买数量');
            // $table->integer('checked')->nullable()->comment('购买数量');
            $table->timestamps();
        });
        Schema::create('contact', function (Blueprint $table) {//联系我们
            $table->increments('id');
            $table->string('image')->nullable()->comment('图片');
            $table->timestamps();
        });
        Schema::create('banner', function (Blueprint $table) {//轮播图
            $table->increments('id');
            $table->string('name')->nullable()->comment('名称');
            $table->string('imgurl')->nullable()->comment('图片地址');
            $table->string('state')->nullable()->default(1)->comment('状态 1正常 2关闭');
            $table->timestamps();
        });
        Schema::create('prefer', function (Blueprint $table) {//优惠券
            $table->increments('id');
            $table->string('name')->nullable()->comment('名称');
            $table->string('adminname')->nullable()->comment('发布人');
            $table->string('price')->nullable()->comment('满多少钱/折扣');
            $table->string('jian')->nullable()->comment('减多少钱');
            $table->string('start_time')->nullable()->comment('开始时间');
            $table->string('end_time')->nullable()->comment('结束时间');
            $table->integer('type')->nullable()->comment('类型 1满减 2折扣');
            $table->integer('state')->nullable()->default(1)->comment('状态 1正常 2过期');
            $table->timestamps();
        });
        Schema::create('preferlog', function (Blueprint $table) {//优惠券记录
            $table->increments('id');
            $table->integer('userid')->nullable()->comment('用户id');
            $table->integer('preferid')->nullable()->comment('优惠券id');
            $table->integer('state')->nullable()->default(1)->comment('状态 1使用 2未使用');
            $table->timestamps();
        });
        Schema::create('delivery', function (Blueprint $table) {//配送管理
            $table->increments('id');
            $table->integer('peisong')->nullable()->comment('配送条件');
            $table->unsignedDecimal('psprice',11,2)->nullable()->comment('配送费');
            $table->integer('type')->nullable()->default(1)->comment('状态 1按订单金额 2按商品份数');
            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('adminuser');//管理员表
        Schema::dropIfExists('users');//用户表
        Schema::dropIfExists('address');//用户地址表
        Schema::dropIfExists('userslog');//用户消费记录
        Schema::dropIfExists('recharge');//充值规则
        Schema::dropIfExists('guige');//产品规格
        Schema::dropIfExists('product');//产品
        Schema::dropIfExists('category');//产品分类
        Schema::dropIfExists('order');//订单表
        Schema::dropIfExists('orderproduct');//订单产品表
        Schema::dropIfExists('cart');//购物车
        Schema::dropIfExists('contact');//联系我们
        Schema::dropIfExists('banner');//轮播图
        Schema::dropIfExists('prefer');//优惠券
        Schema::dropIfExists('preferlog');//优惠券记录
        Schema::dropIfExists('delivery');//配送管理
    }
}
